/*
 * Copyright (C) 2012 Robot.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.yfz.bussearch.ui;


import com.yfz.bussearch.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class LocalSearch extends Activity {
	
	private final String TAG = this.getClass().getSimpleName();
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.local);
		
		Button station = (Button)findViewById(R.id.id_station);
		Button path = (Button)findViewById(R.id.id_path);
		
		station.setOnClickListener(onclick);
		path.setOnClickListener(onclick);
	}
	
	
	OnClickListener onclick = new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			Intent intent = new Intent(LocalSearch.this, WebSearch.class);
			Bundle bundle = new Bundle();
			switch(v.getId()) {
				case R.id.id_station:
					//参数sName代表站点
					//http://m.sz-map.com/search?sName=%E6%9C%A8%E6%B8%8E&ss=%E6%9F%A5%E7%AB%99%E7%82%B9&lName=&number=5
					EditText et = (EditText)findViewById(R.id.et_station);
					if(et.getText().toString().length() == 0) {
						et.setError(getResources().getString(R.string.ERROR_STATION));
						return;
					}
					bundle.putString("URL", "http://m.sz-map.com/search?kw="+et.getText().toString()+"&st=0&paging=y");
					break;
				case R.id.id_path:
					//参数lName代表线路
					//http://m.sz-map.com/search?sName=%E6%9C%A8%E6%B8%8E&ss=%E6%9F%A5%E7%AB%99%E7%82%B9&lName=2&number=5
					EditText et2 = (EditText)findViewById(R.id.et_path);
					String lname = "";
					String input = et2.getText().toString();
					if(input != null && input.length() != 0) {
						lname = input.split("路")[0];
					} else {
						et2.setError(getResources().getString(R.string.ERROR_PATH));
						return;
					}
					bundle.putString("URL", "http://m.sz-map.com/search?kw="+ lname +"&st=1&paging=y");
					break;
			}
			intent.putExtras(bundle);
			startActivity(intent);
		}
	};;;
}
